Skip to content

pkg/sca: add static:lib<name> provides and dependency tracking#2471

Open
smoser wants to merge 5 commits intochainguard-dev:mainfrom
smoser:feat/sca-static-lib-deps
Open

pkg/sca: add static:lib<name> provides and dependency tracking#2471
smoser wants to merge 5 commits intochainguard-dev:mainfrom
smoser:feat/sca-static-lib-deps

Conversation

@smoser
Copy link
Copy Markdown
Contributor

@smoser smoser commented Apr 9, 2026

Scan .a files in standard library directories and emit static:lib provides via SCA, mirroring how so: and pc: provides are generated.

Also parse Libs.private fields from .pc files to discover static:lib runtime dependencies. This generation is gated behind the MELANGE_GENERATE_STATIC_DEPS environment variable (accepted values: "true" or "false"); when disabled, candidate dependencies are only logged so the impact can be evaluated before enabling.

Scan .a files in standard library directories and emit static:lib<name>
provides via SCA, mirroring how so: and pc: provides are generated.

Also parse Libs.private fields from .pc files to discover static:lib<name>
runtime dependencies. This generation is gated behind the
MELANGE_GENERATE_STATIC_DEPS environment variable (accepted values: "true"
or "false"); when disabled, candidate dependencies are only logged so the
impact can be evaluated before enabling.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@smoser smoser requested a review from xnox April 9, 2026 17:48
smoser and others added 4 commits April 9, 2026 13:55
Previously the Libs.private deps were generated for whichever package
contained the .pc file (typically -dev).  Static deps need to land on
the package that owns the .a file (-static) so that linking with
-lfoo -static pulls in transitive static deps automatically.

Search sibling packages for a matching <libname>.pc when a .a file is
found, and derive static:lib<name> runtime dependencies from its
Libs.private field there.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Test provides generation from .a files in standard and non-standard
directories, runtime dep generation from sibling pkg-config Libs.private
fields, the feature flag logging-only mode, and parseEnvBool.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Use strings.FieldsSeq (modernize)
- Preallocate names slice in RelativeNames (prealloc)
- Apply gofumpt formatting

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
py3-seaborn bundles libnpymath.a and libnpyrandom.a from numpy; the new
static library SCA correctly identifies these as vendored static libs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@xnox xnox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For make package/yara, does this produce what you expect?

I got this:

$ cat .PKGINFO 
# Generated by melange
pkgname = yara-dev
pkgver = 4.5.5-r4
arch = x86_64
size = 1327707
origin = yara
pkgdesc = yara dev
url = 
commit = 4a947e9ea1a780700c9a08b6bf3fd6f1b39564a4
maintainer = wolfi
builddate = 1776449776
license = BSD-3-Clause
depend = pc:libcrypto
depend = so:libyara.so.10
depend = yara
provides = pc:yara=4.5.5-r4
provides = static:libyara
datahash = 6189486c4c5d7d42897842cc3c72ec6031391da3a4457278f5c4726659eb8259

And the pc file is this https://apk.chaindag.dev/https/packages.wolfi.dev/os/x86_64/yara-dev-4.5.5-r4.apk@sha1:d9a54cb0de2b4589b0da207a183e1464c0c70036/usr/lib/pkgconfig/yara.pc

prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=/usr/lib

Name: yara
Description: YARA library
URL: https://virustotal.github.io/yara/
Version: 4.5.5
Requires.private:  libcrypto
Cflags: -I${includedir}
Libs: -L${libdir} -lyara
Libs.private:  -lm -lmagic 

Should there be static dependency on magic?

Also not sure how you want to handle Requires.private - as that says that for static linking on needs what ever static linking flags are specified in libcrypto.pc as in like a dep on static:libcrypto.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants